package nbcp.base.extend

import ch.qos.logback.classic.Logger
import nbcp.base.utils.MyUtil
import nbcp.web.HttpContext
import nbcp.web.MyHttpRequestWrapper
import java.io.File


fun Logger.getLoggerFile(configName: String): String {
    var appenderList = this.iteratorForAppenders();
    if (appenderList.hasNext()) {
        var fileAppender = (appenderList.Filter { it.name == configName }.first() as ch.qos.logback.core.rolling.RollingFileAppender)
        return (MyUtil.getPrivatePropertyValue(fileAppender, "currentlyActiveFile") as File).absolutePath
    }

    var parent = MyUtil.getPrivatePropertyValue(this, "parent") as ch.qos.logback.classic.Logger?
    if (parent == null) return "";
    return parent.getLoggerFile(configName);
}

//
//fun <M:MongoBaseEntity<E>,E:IMongoDocument> MongoUpdateClip<M>.whereCorp(corpIdColumn: MongoColumnName): MongoUpdateClip<M> {
//    var request = HttpContext.request;
//    if (request is MyHttpRequestWrapper && request.IsProxy) {
//        var corpId = request.getValue("_corp_id_");
//        if (corpId.HasValue) {
//            this.where(corpIdColumn match corpId);
//        }
//    } else {
//        this.where(corpIdColumn match request.CorpId);
//    }
//
//    return this;
//}
//
//fun <M:MongoBaseEntity<E>,E:IMongoDocument> MongoQueryClip<M,E>.whereCorp(corpIdColumn: String): MongoQueryClip<M,E> {
//    var request = HttpContext.request;
//    if (request is MyHttpRequestWrapper && request.IsProxy) {
//        var corpId = request.getValue("_corp_id_");
//        if (corpId.HasValue) {
//            this.where(corpIdColumn match corpId);
//        }
//    } else {
//        this.where(corpIdColumn match request.CorpId);
//    }
//
//    return this;
//}